package mi.payment.utils;

import android.text.TextUtils;

import mi.payment.settings.MerManagerSettings;
import mi.payment.settings.NetworkParamSettings;
import mi.payment.settings.MerchantSettingsOperation;
import mi.payment.settings.NetworkDataOperations;

/**
 * 必要参数校准
 *
 * @author 47673 on 2017/2/18.
 */
public class MustParameterCalibration {

    public MustParameterCalibration() {

    }

    public static boolean canToNext() {
        NetworkParamSettings networkParam = NetworkDataOperations.getInstance().getNetworkParamSettings();
        MerManagerSettings merManagerSettings = MerchantSettingsOperation.getInstance().getMerManagerSettings();
        return !TextUtils.isEmpty(networkParam.getHostIpAddress())
                && !TextUtils.isEmpty(networkParam.getTPdu())
                && !TextUtils.isEmpty(networkParam.getHostPort())
                && !TextUtils.isEmpty(merManagerSettings.getTerminalNum())
                && !TextUtils.isEmpty(merManagerSettings.getMerchantNum());
    }

    public static boolean canToNext2() {
        NetworkParamSettings networkParam = NetworkDataOperations.getInstance().getNetworkParamSettings();
        return !TextUtils.isEmpty(networkParam.getHostIpAddress())
                && !TextUtils.isEmpty(networkParam.getHostPort())
                && !TextUtils.isEmpty(networkParam.getTPdu());
    }

    public static boolean canToNext3() {
        NetworkParamSettings networkParam = NetworkDataOperations.getInstance().getNetworkParamSettings();
        return !TextUtils.isEmpty(networkParam.getThirdServerIpAddress())
                && !TextUtils.isEmpty(networkParam.getThirdServerPort())
                && !TextUtils.isEmpty(networkParam.getTPdu());
    }

    public static boolean canToNext4() {
        NetworkParamSettings networkParam = NetworkDataOperations.getInstance().getNetworkParamSettings();
        return !TextUtils.isEmpty(networkParam.getHostIpAddress())
                && !TextUtils.isEmpty(networkParam.getTPdu())
                && !TextUtils.isEmpty(networkParam.getHostPort());
    }

    public static boolean canToNext5() {
        NetworkParamSettings networkParam = NetworkDataOperations.getInstance().getNetworkParamSettings();
        return !TextUtils.isEmpty(networkParam.getHostIpAddress())
                && !TextUtils.isEmpty(networkParam.getHostPort());
    }

    /**
     * 检查商户号和终端参数
     */
    public static boolean isNullMerchantAndTerminal() {
        MerManagerSettings settings = MerchantSettingsOperation.getInstance().getMerManagerSettings();
        return isEmpty(settings.getTerminalNum()) || isEmpty(settings.getMerchantNum());
    }

    /**
     * 检查服务器IP和端口
     */
    public static boolean isNullServerIPAndPort() {
        NetworkParamSettings settings = NetworkDataOperations.getInstance().getNetworkParamSettings();
        return isEmpty(settings.getHostIpAddress()) || isEmpty(settings.getHostPort()) || isEmpty(settings.getTPdu());
    }

    private static boolean isEmpty(String str) {
        return TextUtils.isEmpty(str);
    }

}
